package xiangMu.pc;

public class Disk extends Software {    //硬盘盘符
    //每个盘符下有下载的软件和安装的软件，都占用盘符容量
    private Software[] downloadSoftwares = new Software[30];    //盘符下载的软件
    private int countD = 0;
    private Software[] installSoftwares = new Software[30];     //盘符安装的软件
    private int countI = 0;

    public Disk() {
    }

    public Disk(String name, int size) {
        super(name, size);
    }

    public void addDownloadSoftware(Software software) { //下载的软件
        expandDownloadSoftwares();  //先判断数组是否需要扩容
        downloadSoftwares[countD++] = software;
    }

    public void addInstallSoftware(Software software) { //安装后的可执行的exe软件
        expandInstallSoftwares();   //先判断数组是否需要扩容
        installSoftwares[countI++] = software;
    }

    public void show() {
        if (countD != 0) {
            System.out.println("下载的软件如下：");
            for (int i = 0; i < countD; i++)
                System.out.println(downloadSoftwares[i] + "  ");
        }
        if (countI != 0) {
            System.out.println("\n安装的软件如下：");
            for (int i = 0; i < countI; i++)
                System.out.println(installSoftwares[i] + "  ");
        }
        System.out.println("\n剩余空间" + getSize() + "M\n");
    }


    //给盘符下载的软件数组扩容
    public void expandDownloadSoftwares() {
        if (countD >= downloadSoftwares.length) {
            Software[] downloadSoftwares1 = new Software[downloadSoftwares.length * 2];
            for (int i = 0; i < countD; i++) {
                downloadSoftwares1[i] = downloadSoftwares[i];
            }
            downloadSoftwares = downloadSoftwares1;
        }
    }

    //给盘符安装的软件数组扩容
    public void expandInstallSoftwares() {
        if (countI >= installSoftwares.length) {
            Software[] installSoftwares1 = new Software[installSoftwares.length * 2];
            for (int i = 0; i < countI; i++) {
                installSoftwares1[i] = installSoftwares[i];
            }
            installSoftwares = installSoftwares1;
        }
    }


}
